Skip to content

Stack buffer overflow in prepare_input_tensors() due to unchecked memcpy size#16797

Merged
lucylq merged 1 commit intomainfrom
lfq.check-size-before-memcpy
Jan 28, 2026
Merged

Stack buffer overflow in prepare_input_tensors() due to unchecked memcpy size#16797
lucylq merged 1 commit intomainfrom
lfq.check-size-before-memcpy

Conversation

@lucylq
Copy link
Contributor

@lucylq lucylq commented Jan 22, 2026

Summary

Add size checks for int, double, bool before memcpying. Otherwise the input buffer may be larger than the intended size and overwrite adjacent memory.

Test Plan

(executorch) [lfq@devvm20128.prn0 /data/users/lfq/executorch/build (lfq.check-size-before-memcpy)]$ ctest -R extension_runner_util_test -V
...
54: [ RUN      ] InputsTest.DoubleInputWrongSizeFails
54: E 00:00:00.001251 executorch:inputs.cpp:101] Double input at index 2 has size 16, expected sizeof(double) 8
54: [       OK ] InputsTest.DoubleInputWrongSizeFails (0 ms)
...

1/1 Test #54: extension_runner_util_test .......   Passed    0.01 sec

The following tests passed:
        extension_runner_util_test

100% tests passed, 0 tests failed out of 1

Total Test time (real) =   0.01 sec

@pytorch-bot
Copy link

pytorch-bot bot commented Jan 22, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/16797

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure, 8 Pending

As of commit b1dadab with merge base 86b4bea (image):

NEW FAILURE - The following job has failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 22, 2026
@github-actions
Copy link

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@lucylq lucylq marked this pull request as ready for review January 22, 2026 21:22
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Mitigates a stack buffer overflow risk in prepare_input_tensors() by validating scalar input buffer sizes before copying into stack-allocated variables.

Changes:

  • Add strict size checks for Tag::Int (int64_t), Tag::Double (double), and Tag::Bool (bool) inputs prior to memcpy.
  • Return InvalidArgument with a descriptive error when the provided scalar buffer size is unexpected.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mergennachin
Copy link
Contributor

Can you add a regression test?

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lucylq lucylq force-pushed the lfq.check-size-before-memcpy branch from 8c8d7dc to c621f13 Compare January 23, 2026 01:13
Copilot AI review requested due to automatic review settings January 23, 2026 01:14
@lucylq lucylq force-pushed the lfq.check-size-before-memcpy branch from c621f13 to 33aa861 Compare January 23, 2026 01:14
@lucylq lucylq force-pushed the lfq.check-size-before-memcpy branch from 33aa861 to 8090b55 Compare January 23, 2026 01:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lucylq
Copy link
Contributor Author

lucylq commented Jan 23, 2026

Can you add a regression test?

@mergennachin added one for double. Feel like that should be OK as it's the same logic, and adding tests for bool/int would need new models to export_program.py that take in bool/int as input. But let me know what you think

Copy link
Contributor

@larryliu0820 larryliu0820 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some non-blocking comments

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lucylq lucylq force-pushed the lfq.check-size-before-memcpy branch from 801f5a3 to e95bc65 Compare January 27, 2026 23:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lucylq lucylq force-pushed the lfq.check-size-before-memcpy branch from e95bc65 to 1f63405 Compare January 28, 2026 01:26
Copilot AI review requested due to automatic review settings January 28, 2026 01:31
@lucylq lucylq force-pushed the lfq.check-size-before-memcpy branch from 1f63405 to 9c75403 Compare January 28, 2026 01:31
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lucylq lucylq force-pushed the lfq.check-size-before-memcpy branch from 9c75403 to b1dadab Compare January 28, 2026 20:40
@lucylq lucylq merged commit 161d535 into main Jan 28, 2026
169 of 172 checks passed
@lucylq lucylq deleted the lfq.check-size-before-memcpy branch January 28, 2026 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. security-fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants